/**
YASTACS camera yaw animation module.

License: GNU General Public License

YASTACS game
Copyright (C) 2012 Kalman Kiss, kiskami@freemail.hu

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

Contact author at: kiskami@freemail.hu or
Hungary, 8900 Zalaegerszeg
Kakukkfu u 4.
*/
module rendering.CameraYaw;

import std.stdio;

import ogreint.Camera;

import ogreint.Degree;
import ogreint.Radian;

/// yaw speed per sec
immutable float DEF_YAW_SPEED_DEGREE = -0.75;
// yaw how many times per sec
immutable int YAW_PER_SEC = 20;

/**
* Kameraforgatás a függőleges tengely körül.
*/
class CameraYaw {

	this(Camera c, float degpersec_=DEF_YAW_SPEED_DEGREE) {
		cam = c;
		go = false;
		setSpeed(degpersec_);
		cumtime = 0;
	}

	void setSpeed(float degpersec_) {
		radpersec = new Radian(new Degree(degpersec_/YAW_PER_SEC));
//		debug writeln("CameraYaw setSpeed: degpersec=", degpersec_
//					  , ", radpersec/yawpersec=",radpersec.valueRadians());
	}

	void run() { 
		go = true; 
	}

	void stop() { 
		go = false;
		cumtime = 0;
	}

	void update(real elapsedTime) {
		if(go) {
			cumtime += elapsedTime;
//			debug writeln("CameraYaw update, elapsed=", elapsedTime, ", cumtime=",cumtime);
			if(cumtime>=1.0/YAW_PER_SEC) {
//				debug writeln("CameraYaw yaw: ", radpersec);
				cam.yaw(radpersec);
				cumtime = 0;
			}
		}

	}

private:

	bool go;
	Camera cam;
	float cumtime;
	Radian radpersec;
}
